<template>
  <el-checkbox v-model="checked1" label="洗衣机"></el-checkbox>
  <el-checkbox v-model="checked2" label="冰箱" border></el-checkbox>
  <el-checkbox v-model="checked3" label="电视机"></el-checkbox>

  <div>
    <el-checkbox-group v-model="checkedList">
      <el-checkbox label="洗衣机"></el-checkbox>
      <el-checkbox label="冰箱"></el-checkbox>
      <el-checkbox label="禁用" disabled></el-checkbox>
    </el-checkbox-group>
    <el-checkbox-group v-model="checkedList">
      <el-checkbox-button label="洗衣机"></el-checkbox-button>
      <el-checkbox-button label="冰箱"></el-checkbox-button>
      <el-checkbox-button label="电视机"></el-checkbox-button>
    </el-checkbox-group>
    <el-checkbox
      :indeterminate="isIndeterminate"
      v-model="checkedAll"
      @change="handleCheckAllChange"
    >全选</el-checkbox>

    <el-checkbox-group
      v-model="checkedCities"
      @change="handleCheckedCitiesChange"
    >
      <el-checkbox v-for="city in cities" :label="city" :key="city">{{ city }}</el-checkbox>
    </el-checkbox-group>
  </div>


</template>

<script>
const cityOptions = ['上海', '北京', '广州', '深圳']
export default {
  data() {
    return {
      checked1: true,
      checked2: false,
      checked3: false,
      checkedAll: false,
      checkedCities: ['上海', '北京'],
      checkedList: [],
      cities: cityOptions,
      isIndeterminate: true,
    }
  },
  methods: {
    handleCheckAllChange(val) {
      this.checkedCities = val ? cityOptions : []
      this.isIndeterminate = false
    },
    handleCheckedCitiesChange(value) {
      let checkedCount = value.length
      this.checkedAll = checkedCount === this.cities.length
      this.isIndeterminate = checkedCount > 0 && checkedCount < this.cities.length
    }
  }
}
</script>